package edu.njust.underwater.utils;

import edu.njust.underwater.pojo.User;
import edu.njust.underwater.pojo.dto.UserDto;
import org.springframework.beans.BeanUtils;

public class ContextUtils {

    private static final ThreadLocal<UserDto> userContext = new ThreadLocal<>();

    public static void setUser(User user) {

        UserDto userDto = new UserDto();
        BeanUtils.copyProperties(user, userDto);

        userContext.set(userDto);
    }

    public static UserDto getUser() {
        return userContext.get();
    }

}
